package com.atguigu.eduservice.controller.web;

import com.atguigu.common.R;
import com.atguigu.common.cron.bean.FrontPageBean;
import com.atguigu.common.cron.bean.PageListBean;
import com.atguigu.common.jwt.JwtUtils;
import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.service.EduCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author panghl
 * @Date 2021/3/4 17:40
 * @Description TODO
 **/
@RestController
@RequestMapping("/eduservice/commentfront")
@Api(tags = {"edu前台接口"})
public class CommentFrontController {

    @Autowired
    private EduCommentService commentService;

    @ApiOperation(value = "前台分页获取评论")
    @GetMapping("/getFrontComment/{pageNo}/{pageSize}")
    public R getFrontComment(@PathVariable("pageNo") Integer pageNo,
                             @PathVariable("pageSize") Integer pageSize,
                             @RequestParam("courseId") String courseId) {
        FrontPageBean frontPageBean = commentService.getFrontComment(pageNo, pageSize, courseId);
        return R.ok().data(frontPageBean);
    }

    @ApiOperation(value = "回复评论")
    @PostMapping("/commitComment")
    public R commitComment(@RequestBody EduComment eduComment,@ApiIgnore HttpServletRequest request) {
        String memberId = JwtUtils.getMemberIdByJwtToken(request);
        if (StringUtils.isEmpty(memberId)){
            return R.error().code(28004).message("请登录");
        }
        commentService.commitComment(eduComment);
        return R.ok();
    }

}
